<template>
    <card>
        <p slot="title">
            <Icon type="compose"></Icon>
            用户信息
        </p>
        <Form :model="formItem" label-width="120">
            <Row type="flex">
                <Col :span="6">
                    <FormItem label="用户名：">
                        <Input v-model="formItem.username" size="large" placeholder="请填写内容"></Input>
                    </FormItem>
                </Col>
                <Col :span="6">
                    <FormItem label="登录用户名：">
                        <Input v-model="formItem.userLoginName" size="large" placeholder="请填写内容"></Input>
                    </FormItem>
                </Col>
                <Col :span="6">
                    <FormItem label="密码：">
                        <Input v-model="formItem.password" size="large" type="password" placeholder="请填写内容">
                            <Icon type="locked" slot="prepend"></Icon>
                        </Input>
                    </FormItem>
                </Col>
                <Col :span="6">
                    <FormItem label="再次输入密码：">
                        <Input v-model="formItem.rpassword" size="large" type="password" placeholder="请填写内容">
                            <Icon type="locked" slot="prepend"></Icon>
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row type="flex">
                <Col :span="6">
                    <FormItem label="岗位：">
                        <Select size="large" v-model="formItem.job" filterable>
                            <Option :value="1" :key="1">医生</Option>
                            <Option :value="2" :key="2">护士</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col :span="6">
                    <FormItem label="是否后勤人员：">
                        <Checkbox true-value="1" false-value="0" v-model="formItem.isLogistics"></Checkbox>
                    </FormItem>
                </Col>
            </Row>
            <Row type="flex">
                <Col :span="24">
                    <FormItem>
                        <Button @click="save" type="primary">保存</Button>
                        <Button @click="close" type="ghost" style="margin-left: 8px">关闭</Button>
                    </FormItem>
                </Col>
                <Col :span="5">&nbsp;</Col>
                <Col :span="5">&nbsp;</Col>
                <Col :span="5">&nbsp;</Col>
            </Row>
        </Form>
    </card>
</template>

<script>
export default {
    data () {
        return {
            baseURL: '/user',
            readonly: false,
            formItem: {
                username: '',
                userLoginName: '',
                password: '',
                rpassword: '',
                job: '',
                isLogistics: ''
            }
        }
    },
    methods: {
        init () {
            this.$bus.fillData(this.formItem, this.$route.query.row)
            if (this.$route.query.row) {
                this.readonly = true
            }
        },
        save () {
            let url = this.baseURL + '/saveOrUpdate'
            this.$ajax.post(url, this.formItem).then((response) => {
                let {code} = response.data
                if (code === 0) {
                    this.$bus.alert('success', '操作成功')
                    this.$bus.init(this.formItem)
                }
            })
        },
        close () {
            this.$bus.closePageToLink()
        }
    },
    beforeRouteEnter (to, from, next) {
        next(vm => {
            vm.init()
        })
    }
}
</script>

<style>

</style>
